package chamster;

import java.awt.Point;

import chamster.utils.FixedSizeStack;

/**
 * Subclass of the BaseHamster which uses @chamster.utils.FixedSizeStack
 * to maintain a history of visited fields
 * @author mark
 *
 */
public abstract class HistoryHamster extends BaseHamster {

	private final FixedSizeStack<Point> visitedFields;
	
	public HistoryHamster(int historySize) {
		super();
		this.visitedFields = new FixedSizeStack<Point>(Math.min(10, historySize));
	}
	/**
	 * Returns the history of visited fields.
	 * @return
	 */
	public FixedSizeStack<Point> getHistory() {
		return this.visitedFields;
	}
	
	@Override
	public void foreward() throws Exception {
		this.visitedFields.addFirst(super.getLocation());
		super.foreward();
	}
	
	public boolean visitedBefore() {
		return this.visitedFields.contains(super.getLocation());
	}
 }
